package io.renren.modules.business.util;

import io.renren.common.utils.PageUtils;
import io.renren.modules.business.entity.BusProjectTeamEntity;

import java.util.List;
import java.util.Map;

/**
 * 自定义处理并返回page式map集合数据
 *
 * @author liao mengqing
 */
public class PageLastUtil {

    private static int pageSize = 10;
    private static int currPage;
    private static int totalCount;
    private static int start;
    private static int end;

    public static PageUtils getPageUtils(Map<String, Object> params, List<Map<String, Object>> list) {
        util(params, list);
        List<Map<String, Object>> page = list.subList(start, end);
        return new PageUtils(page, totalCount, pageSize, currPage);
    }

    public static PageUtils getProjectPageUtils(Map<String, Object> params, List<BusProjectTeamEntity> list) {
        util(params, list);
        List<BusProjectTeamEntity> page = list.subList(start, end);
        return new PageUtils(page, totalCount, pageSize, currPage);
    }

    public static void util(Map<String, Object> params, List list) {
        currPage = Integer.parseInt((String) params.get("page"));
        totalCount = list.size();
        start = pageSize*(currPage-1);
        end = Math.min((start + 10), totalCount);
    }
}
